/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 underlay_adv_object_image.cpp

	$Header: /heroes4/underlay_adv_object_image.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "underlay_adv_object_image.h"

#include "adv_object_image_visitor.h"

// ------------------------------------------------------------------------------
// Unnamed namespace
// ------------------------------------------------------------------------------

namespace
{
	// ------------------------------------------------------------------------------
	// ------------------------------------------------------------------------------
	int const k_current_format_version = 1;

} // Unnamed namespace

// ------------------------------------------------------------------------------
// t_underlay_adv_object_subimage class members
// ------------------------------------------------------------------------------

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
void t_underlay_adv_object_subimage::draw_to(
	int						frame_num,
	t_screen_rect const &	source_rect,
	t_abstract_bitmap16 &	dest,
	t_screen_point const &	dest_point,
	int						alpha ) const
{
	get_image().draw_to( frame_num, source_rect, dest, dest_point );
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
void t_underlay_adv_object_subimage::draw_to(
	int						frame_num,
	t_abstract_bitmap16 &	dest,
	t_screen_point const &	dest_point ) const
{
	get_image().draw_to( frame_num, dest, dest_point );
}

// ------------------------------------------------------------------------------
// t_underlay_adv_object_image_24 class members
// ------------------------------------------------------------------------------

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
#pragma warning( push )
#pragma warning( disable: 4355 )
t_underlay_adv_object_image_24::t_underlay_adv_object_image_24()
	:	t_underlay_adv_object_image_base<
			t_simple_adv_object_image_24,
			t_underlay_adv_object_image_24,
			t_underlay_adv_object_subimage_24 >( *this )
{
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
t_underlay_adv_object_image_24::t_underlay_adv_object_image_24(
	t_underlay_adv_object_image_24 const &	other )
	:	t_underlay_adv_object_image_base<
			t_simple_adv_object_image_24,
			t_underlay_adv_object_image_24,
			t_underlay_adv_object_subimage_24 >( other, *this )
{
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
t_underlay_adv_object_image_24::t_underlay_adv_object_image_24(
	t_simple_adv_object_image_24 const & other )
	:	t_underlay_adv_object_image_base<
			t_simple_adv_object_image_24,
			t_underlay_adv_object_image_24,
			t_underlay_adv_object_subimage_24 >( other, *this )
{
}

#pragma warning( pop )

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
void t_underlay_adv_object_image_24::accept( t_visitor & visitor )
{
	visitor.visit( *this );
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
void t_underlay_adv_object_image_24::accept( t_visitor & visitor ) const
{
	visitor.visit( *this );
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
t_underlay_adv_object_image_24::t_clone_ptr
t_underlay_adv_object_image_24::clone() const
{
	return t_clone_ptr( new t_underlay_adv_object_image_24( *this ) );
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
t_underlay_adv_object_image_24::t_clone_16_ptr
t_underlay_adv_object_image_24::clone_as_16() const
{
	return t_clone_16_ptr( new t_underlay_adv_object_image( *this ) );
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
bool t_underlay_adv_object_image_24::read( std::streambuf & stream )
{
	int version;
	try
	{
		version = get< t_uint16 >( stream );
	}
	catch ( t_streambuf_read_failure const & )
	{
		return false;
	}

	return read_version( stream, version );
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
bool t_underlay_adv_object_image_24::read_version(
	std::streambuf &	stream,
	int					version )
{
	if ( version < 1 )
		return t_simple_adv_object_image_24::read_version( stream, 0 );
	return t_simple_adv_object_image_24::read( stream );
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
bool t_underlay_adv_object_image_24::write( std::streambuf & stream ) const
{
	try
	{
		put< t_uint16 >( stream, k_current_format_version );
	}
	catch ( t_streambuf_write_failure const & )
	{
		return false;
	}

	return t_simple_adv_object_image_24::write( stream );
}

// ------------------------------------------------------------------------------
// t_underlay_adv_object_image class members
// ------------------------------------------------------------------------------

#pragma warning( push )
#pragma warning( disable: 4355 )
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
t_underlay_adv_object_image::t_underlay_adv_object_image()
	:	t_underlay_adv_object_image_base<
			t_simple_adv_object_image,
			t_underlay_adv_object_image,
			t_underlay_adv_object_subimage >( *this )
{
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
t_underlay_adv_object_image::t_underlay_adv_object_image(
	t_underlay_adv_object_image const &	other )
	:	t_underlay_adv_object_image_base<
			t_simple_adv_object_image,
			t_underlay_adv_object_image,
			t_underlay_adv_object_subimage >( other, *this )
{
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
t_underlay_adv_object_image::t_underlay_adv_object_image(
	t_underlay_adv_object_image_24 const &	other )
	:	t_underlay_adv_object_image_base<
			t_simple_adv_object_image,
			t_underlay_adv_object_image,
			t_underlay_adv_object_subimage >( other, *this )
{
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
t_underlay_adv_object_image::t_underlay_adv_object_image(
	t_simple_adv_object_image const & other )
	:	t_underlay_adv_object_image_base<
			t_simple_adv_object_image,
			t_underlay_adv_object_image,
			t_underlay_adv_object_subimage >( other, *this )
{
}
#pragma warning( pop )

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
void t_underlay_adv_object_image::accept( t_visitor & visitor )
{
	visitor.visit( *this );
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
void t_underlay_adv_object_image::accept( t_visitor & visitor ) const
{
	visitor.visit( *this );
}

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
t_underlay_adv_object_image::t_clone_ptr
t_underlay_adv_object_image::clone() const
{
	return t_clone_ptr( new t_underlay_adv_object_image( *this ) );
}
